package org.ielts.domain.base;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.ielts.domain.Atom;
import org.ielts.domain.log.OrderLessonLog;

@Entity
public class Lesson extends Atom {

	private float lessonHours;

	int no;
	Date beginTime;
	Date endTime;
	private boolean canceled;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "lesson")
	private Set<OrderLessonLog> orders = new HashSet<OrderLessonLog>(0);

	@ManyToOne(fetch = FetchType.EAGER)
	Classroom classroom;

	@ManyToOne(fetch = FetchType.EAGER)
	CourseType courseType;

	@OneToMany()
	@JoinColumn(name = "LESSON_ID")
	private Set<Teaching> teachings = new HashSet<Teaching>();

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public String getBeginTimeHHMM() {
		if (beginTime == null) {
			return "";
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		return simpleDateFormat.format(beginTime);
	}

	public String getEndTimeHHMM() {
		if (endTime == null) {
			return "";
		}
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		return simpleDateFormat.format(endTime);
	}

	public String getTimespan() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		return simpleDateFormat.format(beginTime) + "-" + simpleDateFormat.format(endTime);
	}

	public String getDate() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		return simpleDateFormat.format(beginTime);
	}

	public String getBeginTimeStr() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		return simpleDateFormat.format(beginTime);
	}

	public String getEndTimeStr() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
		return simpleDateFormat.format(endTime);
	}

	public Date getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(Date beginTime) {
		this.beginTime = beginTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Classroom getClassroom() {
		return classroom;
	}

	public void setClassroom(Classroom classroom) {
		this.classroom = classroom;
	}

	public CourseType getCourseType() {
		return courseType;
	}

	public void setCourseType(CourseType courseType) {
		this.courseType = courseType;
	}

	public Set<Teaching> getTeachings() {
		return teachings;
	}

	public void setTeachings(Set<Teaching> teachings) {
		this.teachings = teachings;
	}

	public boolean isCanceled() {
		return canceled;
	}

	public void setCanceled(boolean canceled) {
		this.canceled = canceled;
	}

	public Set<OrderLessonLog> getOrders() {
		return orders;
	}

	public void setOrders(Set<OrderLessonLog> orders) {
		this.orders = orders;
	}

	public float getLessonHours() {
		return lessonHours;
	}

	public void setLessonHours(float lessonHours) {
		this.lessonHours = lessonHours;
	}
}
